package com.example.baiyu.nestedscrollingdemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.baiyu.nestedscrollingdemo.R;

import java.util.List;

/**
 * Created by fanliang on 18/5/17.
 */

public class RcvAdapter extends RecyclerView.Adapter<RcvAdapter.ItemVH> {

    private  List<String> list;
    public RcvAdapter(List<String> list) {
        this.list = list;
    }

    @Override
    public ItemVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LinearLayout.inflate(parent.getContext(), R.layout.layout, null);
        return new ItemVH(view);
    }

    @Override
    public void onBindViewHolder(ItemVH holder, int position) {
        holder.tvItem.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ItemVH extends RecyclerView.ViewHolder {

        public TextView tvItem;
        public ItemVH(View itemView) {
            super(itemView);
            tvItem = itemView.findViewById(R.id.tv_item);
        }
    }
}
